@extends('Admin.Layout.main')
@section('privateheader')
    <link rel="stylesheet" href="{{__BASE__}}/admin/plugins/multiSelect/multi-select-metro.css">
@endsection
@section('content')
    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-6">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{$data['pageOrButton']}} 开通城市</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form role="form" action="/admini/setarea" method="post" id="setarea-form">
                                    {{ method_field('PUT') }}
                                    <input type="hidden" name="_token" value="{{csrf_token()}}">
                                    <div class="box-body">
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">当前城市<font color="red">【左边未开通 右边为已开通】</font></label><br>
                                                <select multiple="multiple" id="my_multi_select1" name="group_servant_id[]">
                                                    @if(!empty($data['list']))
                                                        @foreach($data['list'] as $k => $v)
                                                            <option <?php if(!empty($data['select']) && in_array($v->id,$data['select'])){ echo 'selected="selected"';}?> value="{{$v->id or ''}}">{{$v->name or ''}}</option>
                                                        @endforeach
                                                    @endif
                                                </select>
                                        </div>
                                    </div>
                                    <!-- /.box-body -->

                                    <div class="box-footer">
                                        <button class="btn btn-primary" type="submit">{{$data['pageOrButton']}}</button>
                                        <a href="/admini/adminuser" class="btn bg-olive">返回列表</a>
                                    </div>
                                </form>
                </div>
                <!-- /.box -->
            </div>
            <!--/.col (left) -->
        </div>
        <!-- /.row -->
    </section>
@endsection
@section('privatefooter')
    <!-- jquery-validator -->
    <script src="{{__BASE__}}/admin/plugins/jquery-validate/jquery.validate.min.js"></script>
    <script src="{{__BASE__}}/admin/plugins/jquery-validate/localization/messages_zh.min.js"></script>
    <script type="text/javascript" src="{{__BASE__}}/admin/plugins/multiSelect/jquery.multi-select.js"></script>
    <script type="text/javascript" src="{{__BASE__}}/admin/dist/js/form-validate/setarea.js"></script>
    <script>
        $(function () {
            $("#my_multi_select1").multiSelect();
            //选择主角色联动附属角色
            $("select[name='group_master_id']").on("change",function(){
                //改变主角色后初始化附属角色
                $("#ms-my_multi_select1 .ms-selectable ul li").show().removeClass("ms-selected");
                $("#ms-my_multi_select1 .ms-selection ul li").hide().removeClass("ms-selected");
                //获取当前改变值
                var value = $(this).val();
                if(value.length < 1){
                    alert("请勿选择空");
                }else{
                    var id = value.split("_")[1];
                    $("select[name='group_servant_id[]'] option").each(function(n){
                        var value = $(this).val();
                        if(id == value){
                            //附属角色不能选中主角色
                            $(this).prop("selected",false);
                        }
                    });
                    //左侧选择栏
                    $("#ms-my_multi_select1 .ms-selectable ul li").each(function(n){
                        var left_split_id = $(this).attr("id").split("-")[0];

                        if(left_split_id == id)
                        {
                            $(this).hide();
                        }
                    });
                    //右侧选择栏
                    $("#ms-my_multi_select1 .ms-selection ul li").each(function(n){
                        var right_split_id = $(this).attr("id").split("-")[0];
                        if(right_split_id == id)
                        {
                            $(this).hide();
                        }
                    });
                }
            });
        });
    </script>
@endsection